Passed
Push — main ( a5cb81...de7f7b )
by Bjarn
04:10 queued 02:01
created

Elasticsearch.install   A

Complexity

Conditions 1

Size

Total Lines 7
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 7
dl 0
loc 7
rs 10
c 0
b 0
f 0
1
import {writeFileSync} from 'fs'
2
import nginxElasticsearchConf from '../templates/nginx/elasticsearch'
3
import {client} from '../utils/os'
4
import {getConfig, jaleNginxAppsPath} from '../utils/jale'
5
import Nginx from './nginx'
6
import Service from './service'
7
8
class Elasticsearch extends Service {
9
    requireRoot = false
10
    service = 'elasticsearch'
11
12
    // TODO: These paths should be using the Client class. Otherwise they won't work cross platform.
13
    configPath = '/usr/local/etc/elasticsearch/elasticsearch.yml'
14
    dataPath = 'path.data'
15
    dataRootPath = '/usr/local/var'
16
    nginxConfigPath = `${jaleNginxAppsPath}/elasticsearch.conf`
17
18
    install = async (): Promise<boolean> => {
19
        await client().packageManager.install('java', true)
20
        await client().packageManager.install('homebrew/cask-versions/adoptopenjdk8', true)
21
        await client().packageManager.install('libyaml', false)
22
        await client().packageManager.install(this.service, false)
23
24
        return true
25
    }
26
27
    configure = async (): Promise<boolean> => {
28
        const config = await getConfig()
29
        await writeFileSync(this.nginxConfigPath, nginxElasticsearchConf(config.tld))
30
        await (new Nginx).restart()
31
32
        return true
33
    }
34
35
}
36
37
export default Elasticsearch